﻿<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="javax.cache.*" %>
<%@ page import="com.byjyate.rssdreamwork.*" %>
<%@ page import="com.byjyate.rssdreamwork.RepositoryBase" %>
<%
	long itemsperpage = 50;
	try {
		long pg = 1;
		try {
			pg = Long.parseLong(request.getParameter("page"));
		} catch (Exception e) {}
		Cache cache = null;
		CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
		cache = cacheFactory.createCache(Collections.emptyMap());
		CacheStatistics stats = cache.getCacheStatistics();

		int hits = stats.getCacheHits(), misses = stats.getCacheMisses();
		double hitrate = hits + misses != 0 ? (double)hits / (hits + misses) * 100 : 0;
		DecimalFormat digits = new DecimalFormat("0.00");

		PageInfoRepository pageInfoRepo = new PageInfoRepository();
		List<PageInfo> pageInfos = pageInfoRepo.getPageInfos();
		long waitingnum = pageInfoRepo.getWaitinglistLength();
		long itemnum = pageInfos.size();
%>
		当前内存缓存中共有 <%= stats.getObjectCount() %> 项，缓存命中 <%= hits %> 次，未命中 <%= misses %> 次，命中率为 <%= digits.format(hitrate) %>%<br>
		<a href="/tasks/clearcache">清空缓存</a>  <a href="/tasks/updateallrss?donow=false">刷新全部 RSS</a><br>
		当前数据库下载队列中共有 <%= itemnum %> 项任务，其中 <%= waitingnum %> 项未完成，<%= itemnum - waitingnum %> 项已完成<br>
		<br>
		<table cellspacing="15">
			<tr>
				<td>ID</td>
				<td>地址</td>
				<td>添加时间</td>
				<td>状态</td>
			</tr>
<%
			long num = 0;
			for (PageInfo pageInfo : pageInfos)
			{
				num++;
				if (num > pg * itemsperpage || num > itemnum)
					break;
				if (num >= (pg - 1) * itemsperpage) {
%>
					<tr>
						<td><%= itemnum - num + 1 %></td>
						<td><%= pageInfo.getUrl() %></td>
						<td><%= DateTimeProcesser.FormatInChn(pageInfo.getAddTime()) %></td>
						<td><%= pageInfo.getStatus() %></td>
					</tr>
<%
				}
			}
%>
		</table>
<%
		if (itemnum > 0)
%>
		<p align="center">
<%
			long pages = (itemnum - 1) / itemsperpage + 1;
			for (long i = 1;i <= pages; i++) {
				if (i != pg) {
%>
					<a href="/admin/admin.jsp?page=<%= i %>">第 <%= i %> 页</a>  
<%
				}
				else {
%>
					第 <%= i %> 页  
<%					
				}
			}
%>
		</p>
<%
	} catch (Exception e) {
%>
		<h1>抱歉，发生错误</h1>
<%
	}
%>
